package com.ajview.common.core.domain.enums;

import com.ajview.common.utils.MessageUtils;
import com.ajview.common.utils.StringUtils;

/**
 * @author ZhangJunJie
 * @Date 2022-04-26
 * <p>
 * 概要：通用返回枚举
 */

public enum ResultCodeEnum {
    // ===============2000============
    REQUEST_SUCCESS(2000, "操作成功", "server.success"),
    LOGIN_SUCCESS(2000, "登录成功", "user.login.sucs"),
    LOGOUT_SUCCESS(2000, "成功退出", "user.login.logout.sucs"),
    //==============4xxx===============
    UNAUTHORIZED(4001, "认证失败，无法访问系统资源", "user.login.unauthorized"),
    NO_UNAUTHORIZED(4002, "请求错误或无权访问，无法访问系统资源", "user.login.no_unauthorized"),

    LOGIN_TIMEOUT(4003, "认证错误，认证信息已过期，请退出后重新登录", "user.login.login_timeout"),

    LOGIN_PARAMETER_WRONGFUL(4005, "认证错误，认证参数不合法禁止访问", "user.login.login_parameter_wrongful"),
    ILLEGAL_REQUEST_METHOD(4006, "非法请求方式，禁止访问系统资源", "system.error.illegal_request_method"),
    EXCEPTION_GLOBLE(4007, "请求错误，请稍后重试！", "system.error.exception_globle"),
    LOGIN_AUTH_EXCEPTION(4008, "认证失败，用户名或密码错误", "user.login.login_auth_exception"),


    //==============5xxx================
    REQUEST_ERROR(5000, "服务器内部错误", "server.error"),

    REQUEST_PARAMS_ERROR(5005, "参数校验错误", "system.require.request_params_error");


    private Integer code;
    private String messageCode;
    private String defaultMessage;


    ResultCodeEnum(Integer code, String defaultMessage, String messageCode) {
        this.code = code;
        this.defaultMessage = defaultMessage;
        this.messageCode = messageCode;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessageCode() {
        return messageCode;
    }

    public String getMessage() {
        String message = null;
        if (!StringUtils.isEmpty(this.messageCode)) {
            message = MessageUtils.message(messageCode);
        }
        if (StringUtils.isEmpty(message)) {
            message = defaultMessage;
        }
        return message;
    }
}
